package algorithms.que14;

import edu.princeton.cs.algs4.StdOut;
import edu.princeton.cs.algs4.StdRandom;
import edu.princeton.cs.algs4.Stopwatch;

/**
 * @功能
 * @创建时间 2020/9/20
 */
public class E1d4d39 {
    public static double timeTrial(int N)
    {
        int MAX=1000000;
        int[] a=new int[N];
        for (int i=0;i<N;i++)
            a[i]= StdRandom.uniform(-MAX,MAX);
        Stopwatch timer=new Stopwatch();
        int cnt=ThreeSum.count(a);
        return timer.elapsedTime();
    }
    //
    public static void main(String[] args)
    {
        //
        double prev=0.0;
        double time=0.0;
        for (int i=10;i<=1000;i=10*i)
        {
            prev=0.0;
            for(int j=1;j<=i;j++)
                prev=prev+timeTrial(125);
            //

            for (int N=250;N<=8000;N+=N)
            {
                time=0.0;
                for(int k=1;k<=i;k++)
                {
                    time=time+timeTrial(N);
                }//for k
                StdOut.printf("runTime=%5d N=%6d timeSecond=%7.1f  ratio=%5.1f\n",i,N,time/i,time/prev);
                prev=time;
            }//for N
        }//for i
    }//end main
}
